package com.hiwan.unions.adapter.fragmentAdapters;

import android.content.Context;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hiwan.unions.R;
import com.hiwan.unions.adapter.bean.EventFragmentBean;
import com.hiwan.unions.adapter.bean.HomeBottonBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by llg on 2016/3/19.
 */
public class EventAdapter extends BaseAdapter {
    private List<EventFragmentBean> cDates = new ArrayList<EventFragmentBean>();
    private Context mContext;
    protected SharedPreferences userInfo;

    public EventAdapter(Context contex, List<EventFragmentBean> cDates) {
        this.mContext = contex;
        this.cDates = cDates;
    }

    @Override
    public int getCount() {
        return cDates.size();
    }

    @Override
    public Object getItem(int position) {
        return cDates.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_event_fragment, null);
            holder.ItemCityView = (TextView) convertView.findViewById(R.id.ItemCityView);
            holder.ItemDate = (TextView) convertView.findViewById(R.id.ItemDate);
            holder.imageView = (ImageView) convertView.findViewById(R.id.imageView);
            holder.ItemNumber = (TextView) convertView.findViewById(R.id.ItemNumber);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        setData(holder, position);
        return convertView;
    }

    /**
     * 设置viewHolder的数据  1型
     *
     * @param holder
     * @param itemIndex
     */
    private void setData(ViewHolder holder, int itemIndex) {
        holder.ItemCityView.setText(cDates.get(itemIndex).getTitle());
        holder.imageView.setImageResource(cDates.get(itemIndex).getImage());
        holder.ItemNumber.setText("剩余名额："+cDates.get(itemIndex).getNumber());
        holder.ItemDate.setText("活动时间："+cDates.get(itemIndex).getDate());

    }

    private class ViewHolder {
        private TextView ItemNumber;
        private TextView ItemDate;
        private TextView ItemCityView;
        private ImageView imageView;

    }
}